From the Firehose

Laravel 9 Vue JS Live Search

Step 1: Install Laravel 9 App

    composer create-project --prefer-dist laravel/laravel blogf

Step 2: Connecting App to Database .env

    DB_CONNECTION=mysql 
    DB_HOST=127.0.0.1 
    DB_PORT=3306 
    DB_DATABASE=here database name here
    DB_USERNAME=here database username here
    DB_PASSWORD=here database password here

Step 3: Run Make auth Command

    cd blog
    composer require laravel/ui --dev
    php artisan ui vue --auth

Step 4: Create Model and Migration and Controller

    php artisan make:model Post -fm

          Open create_posts_table.php migration:

     public function up()
    {
       Schema::create('posts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->string('slug');
            $table->unsignedBigInteger('user_id');
            $table->timestamps();
      });
    }
     php artisan migrate 

           Navigate to app/Models/Post.php:

    <?php
 
        namespace App\Models;
        
        use Illuminate\Database\Eloquent\Factories\HasFactory;
        use Illuminate\Database\Eloquent\Model;
        
        class Post extends Model
        {
            use HasFactory;
            protected $guarded = [];
        }    

         Factory   

        Navigate to database/factories and open PostFactory.php:        

    public function definition()
    {
        $title = fake()->sentence();
        $slug = Str::slug($title);
        return [
            'title' => $title,
            'slug' => $slug,
            'user_id' => 1
        ];
    }    
    php artisan tinker
    //and then
    App\Models\User::factory()->count(10)->create();
    App\Models\Post::factory()->count(30)->create();
    exit

    

Category: Laravel | Comments: 2

Comments: 2

peturik 2022-11-27 14:24:40

This is third comment

peturik 2022-11-27 14:24:12

This is second comment

About

Customize this section to tell your visitors a little bit about your publication, writers, content, or something else entirely. Totally up to you.